package net.starwifi.duobao.web.db;

import net.starwifi.duobao.entity.DBOrder;
import net.starwifi.duobao.entity.DBTimes;
import net.starwifi.duobao.mvc.BaseController;
import net.starwifi.duobao.service.DBOrderService;
import net.starwifi.duobao.service.DBTimesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/12/1.
 */
@Controller("apiDBCalcController")
@RequestMapping("/db")
public class CalcController extends BaseController {

    @Autowired
    DBTimesService dbTimesService;

    @Autowired
    DBOrderService dbOrderService;

    @RequestMapping(value = "/calc-{id}-{timesNo}", method = RequestMethod.GET)
    public String product(Model model,@PathVariable Long id,@PathVariable String timesNo) {
        DBTimes dbTimes=dbTimesService.findByTimesNo(timesNo);  //很卡顿
        List<net.starwifi.duobao.mvc.Order> orderBy=new ArrayList<net.starwifi.duobao.mvc.Order>();
        orderBy.add(net.starwifi.duobao.mvc.Order.desc("id"));
        List<DBOrder> orderList=dbOrderService.getListData(0, 20, "o.timesNo=?1 and o.paymentStatus=?2", new Object[]{dbTimes.getTimesNo(), 1}, orderBy);
        model.addAttribute("dbTimes",dbTimes);
        model.addAttribute("orderList",orderList);
        return "/db/calc";
    }

}
